<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<title>秒杀</title>
	<link href="http://cdn.phpdongyi.cn/css/timeTo.css" type="text/css" rel="stylesheet"/>
	<link href="http://cdn.phpdongyi.cn/css/style.css" type="text/css" rel="stylesheet"/>
	<script src="http://cdn.phpdongyi.cn/js/jquery.min.js"></script>
	<script src="http://cdn.phpdongyi.cn/js/jquery.time-to.min.js"></script>
</head>

<body>
<div id="box">
	<img class="ms_pic"  src="http://cdn.phpdongyi.cn/img/huawei.jpg" />
	<div id="ms"> </div>
</div>

<div  class="countdown" id="countdown"></div>
</body>

<script>

$.get("getTime",function (res) {
	if(res.status=='fail'){
		alert(res.msg);
		return;
	}

	tt = res.time;

	if(tt<0){
		tt='stop';
	}
	$('#countdown').timeTo(tt,function(){
		$('#ms').append('<img class="ms_start"  src="http://cdn.phpdongyi.cn/img/start.jpg" />');
	});
});

$("#ms").on("click","img",function () {
	console.log(localStorage.getItem("clk"));
	if(localStorage.getItem("clk")==null){
		localStorage.setItem("clk",true);
		$.get("getSecKillPath",{id:1},function (res) {
			if(res.status=='success'){
				console.log(res.url);
				$.ajax({
					url: "go/"+res.url+"/order", // 请求的 URL
					type: 'POST', // 请求方法
					dataType: 'json', // 预期服务器返回的数据类型
					data: {
						id:1,
					}, // 要发送到服务器的数据
					success: function(response) {
						console.log('Success:', response);
					},
					error: function(xhr, status, error) {
						console.error('Error:', error);
					}
				});
			}
		});
	}else {
		$("#ms").html("");
		alert("活动结束");
	}
});

</script>
</html>